package Annotation;

/**
 * @Author shangchao
 * @Date 2020/9/25 19:28
 */
public class ContainerDemo {

    public static void usingSimpleContainer(){
        ServiceA a = SimpleContainer.getInstance(ServiceA.class);
        a.callB();

        ServiceB b = SimpleContainer.getInstance(ServiceB.class);

        if(b != a.getB()){
            System.out.println("SimpleContainer: different instances");
        }
    }

    //使用SimpleContainer2，能够判断是否有SimpleSingleton注解，这样ServiceB是单例的，只会被实例化一次
    public static void usingSimpleContainer2(){
        ServiceA a = SimpleContainer2.getInstance(ServiceA.class);
        a.callB();

        ServiceB b = SimpleContainer2.getInstance(ServiceB.class);

        if(b == a.getB()){
            System.out.println("SimpleContainer2: same instances");
        }
    }

    public static void main(String[] args) {
//        usingSimpleContainer();
        usingSimpleContainer2();
    }
}
